package com.mutual.assistance.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {

    public static final String DEF_ERROR_MESSAGE = "系统繁忙，请稍候再试";
    public static final String HYSTRIX_ERROR_MESSAGE = "请求超时，请稍候再试";
    public static final String SUCCESSFULLY_DELETED = "删除成功";
    public static final String UPDATE_SUCCESS = "更新成功";
    public static final String ADDED_SUCCESSFULLY = "添加成功";
    public static final String QUERY_WAS_SUCCESSFUL = "查询成功";
    public static final String LOGIN_WAS_SUCCESSFUL = "登录成功";
    public static final String REGISTER_WAS_SUCCESSFUL = "注册成功";
    public static final String LOGIN_WAS_OUT_SUCCESSFUL = "登出成功";
    public static final String SUCCESSFULLY_SENT = "发送邮件成功";
    public static final String AUTHENTICATION_FAILED = "认证失败";

    public static final String AUDIT_FALSE = "审核成功";
    public static final String COMMIT_SUCCESS = "提交成功";

    public static final String Execute_to_obtain_an_empty_object = "执行对象为空，请检查上传参数是否正确";

    public static final String UNKNOWN_ERROR = "未知的错误";


    public static final int SUCCESS_CODE = 200;
    public static final int FAIL_CODE = -1;
    public static final int TIMEOUT_CODE = -2;
    public static final int VALID_EX_CODE = -9;
    public static final int OPERATION_EX_CODE = -10;

    @ApiModelProperty(value = "响应编码")
    private int code;

    @ApiModelProperty(value = "响应数据")
    private T data;

    @ApiModelProperty(value = "提示消息")
    private String msg;

    public R() {
    }

    public R(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public R(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static <E> R<E> result(int code, E data, String msg) {
        return new R<>(code, data, msg);
    }

    public static <E> R<E> success(E data, String msg) {
        return new R<>(SUCCESS_CODE, data, msg);
    }

    public static <E> R<E>  fail(int code, String msg) {
        return new R<>(code, null, msg);
    }

}
